//
//  ContactUSCell.swift
//  swiftProject
//
//  Created by ZhangSai on 2021/6/6.
//

import UIKit

class ContactUSCell: UITableViewCell {

    typealias ContactUSCellBlock = (_ cell:UITableViewCell) -> Void
    var contactUSCellBlock : ContactUSCellBlock!
    
    override func awakeFromNib() {
        super.awakeFromNib()
        
        self.contentView.addSubview(self.phoneTextLab)
        self.contentView.addSubview(self.callPhoneView)
        self.callPhoneView.addSubview(self.phoneBtn)
        self.callPhoneView.addSubview(self.callPhoneLab)

        self.phoneTextLab.snp.makeConstraints { (make) in
            make.left.equalTo(self.contentView.snp.left).offset(50)
            make.centerY.equalTo(self.contentView.snp.centerY)
            make.width.lessThanOrEqualTo(10)
            make.height.equalTo(20)
        }
        
        self.callPhoneView.snp.makeConstraints { (make) in
            make.left.equalTo(self.phoneTextLab.snp.right).offset(20)
            make.centerY.equalTo(self.contentView.snp.centerY)
            make.height.equalTo(24)
        }
        
        self.phoneBtn.snp.makeConstraints { (make) in
            make.left.equalTo(self.callPhoneView.snp.left).offset(5)
            make.width.equalTo(10)
            make.centerY.equalTo(self.callPhoneView.snp.centerY)
            make.height.equalTo(24)
        }
        
        self.callPhoneLab.snp.makeConstraints { (make) in
            make.left.equalTo(self.phoneBtn.snp.right).offset(5)
            make.width.lessThanOrEqualTo(10)
            make.centerY.equalTo(self.callPhoneView.snp.centerY)
            make.height.equalTo(24)
            make.right.equalTo(self.callPhoneView.snp.right)
        }
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
    @objc func clickCallPhone() {
        if (self.contactUSCellBlock != nil) {
            self.contactUSCellBlock(self)
        }
    }
    
    @objc func handlerTap() {
        if (self.contactUSCellBlock != nil) {
            self.contactUSCellBlock(self)
        }
    }
    
    lazy var phoneTextLab:UILabel = {
        let phoneTextLab = UILabel()
        phoneTextLab.textColor = UIColor.black
        phoneTextLab.font = UIFont.boldSystemFont(ofSize: 18)
        phoneTextLab.textAlignment = .center
        return phoneTextLab
    }()

    lazy var callPhoneView:UIView = {
        let callPhoneView = UIView()
        callPhoneLab.isUserInteractionEnabled = true
        let gesture:UITapGestureRecognizer = UITapGestureRecognizer.init(target: self, action: #selector(handlerTap))
        callPhoneView.addGestureRecognizer(gesture)
        callPhoneView.layer.cornerRadius = 12
        return callPhoneView
    }()
    
    lazy var phoneBtn:UIView = {
        let phoneBtn = UIButton.init(type: .custom)
        phoneBtn.setImage(UIImage.init(named: "login_callPhone"), for: .normal)
        phoneBtn.addTarget(self, action: #selector(clickCallPhone), for: .touchUpInside)
        return phoneBtn
    }()
    
    lazy var callPhoneLab:UILabel = {
        let callPhoneLab = UILabel()
        callPhoneLab.font = UIFont.systemFont(ofSize: 12)
        callPhoneLab.textColor = UIColor.black
        return callPhoneLab
    }()
}
